        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>Matrix22 class / box2d_html Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d_html" data-type="Matrix22">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d_html.html">box2d_html</a> &rsaquo; <a href="../box2d_html/Matrix22.html">Matrix22</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>Matrix22</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<p>A 2x2 matrix class.</p>
<pre class="source">
class Matrix22 {
  Vector col1;
  Vector col2;

  /**
   * Constructs a new Matrix. Defaults to both columns being default vectors.
   */
  Matrix22([Vector c1 = null, Vector c2 = null]) {
    if (c1 == null) c1 = new Vector();
    if (c2 == null) c2 = new Vector();
    col1 = c1;
    col2 = c2;
  }

  /** Constructs a new Matrix22 representing an angle. */
  Matrix22.fromAngle(num angle)
      : col1 = new Vector(), col2 = new Vector() {
    setAngle(angle);
  }

  /** Create a new Matrix equal to the given Matrix. */
  Matrix22.copy(Matrix22 other)
      : col1 = new Vector.copy(other.col1),
        col2 = new Vector.copy(other.col2);

  /**
   * Returns true if given object is a Matrix22 and its col1 and col2 are equal
   * to the col1 and col2 of this Matrix22.
   */
  bool operator ==(other) {
    return other is Matrix22 &amp;&amp; col1 == other.col1 &amp;&amp; col2 == other.col2;
  }

  /** Set as a matrix representing a rotation. */
  void setAngle(num angle) {
    num cosin = Math.cos(angle);
    num sin = Math.sin(angle);
    col1.setCoords(cosin, sin);
    col2.setCoords(-sin, cosin);
  }

  /** Set as the identity matrix. */
  void setIdentity() {
    col1.setCoords(1, 0);
    col2.setCoords(0, 1);
  }

  /**
   * Sets this matrix's columns equal to the given vectors, respectively.
   */
  void setFromColumns(Vector v1, Vector v2) {
    col1.setFrom(v1);
    col2.setFrom(v2);
  }

  /**
   * Multiply this matrix by a vector. Return the result through the given out
   * parameter.
   */
  void multiplyVectorToOut(Vector v, Vector out) {
    num tempy = col1.y * v.x + col2.y * v.y;
    out.x = col1.x * v.x + col2.x * v.y;
    out.y = tempy;
  }

  /** Sets this matrix to be equal to the given matrix. */
  void setFrom(Matrix22 matrix) {
    col1.setFrom(matrix.col1);
    col2.setFrom(matrix.col2);
  }

  /**
   * Multiply the given vector by the transpose of the given matrix and store
   * the result in the given parameter out.
   */
  static void mulTransMatrixAndVectorToOut(Matrix22 matrix, Vector vector,
      Vector out) {
    num outx = vector.x * matrix.col1.x + vector.y * matrix.col1.y;
    out.y = vector.x * matrix.col2.x + vector.y * matrix.col2.y;
    out.x = outx;
  }

  /**
   * Multiply the given vector by the given matrix and store
   * the result in the given parameter out.
   */
  static void mulMatrixAndVectorToOut(Matrix22 matrix, Vector vector,
      Vector out) {
    num tempy = matrix.col1.y * vector.x + matrix.col2.y * vector.y;
    out.x = matrix.col1.x * vector.x + matrix.col2.x * vector.y;
    out.y = tempy;
  }

  /** Inverts this Matrix. */
  Matrix22 invertLocal() {
    num a = col1.x, b = col2.x, c = col1.y, d = col2.y;
    num det = a * d - b * c;
    if (det != 0) {
      det = 1.0 / det;
    }
    col1.x = det * d;
    col2.x = -det * b;
    col1.y = -det * c;
    col2.y = det * a;
    return this;
  }

  /** Adds the given matrix to this matrix. Returns this matrix. */
  Matrix22 addLocal(Matrix22 other) {
    col1.x += other.col1.x;
    col1.y += other.col1.y;
    col2.x += other.col2.x;
    col2.y += other.col2.y;
    return this;
  }

  void solveToOut(Vector b, Vector out) {
    num a11 = col1.x, a12 = col2.x, a21 = col1.y, a22 = col2.y;
    num det = a11 * a22 - a12 * a21;
    if (det != 0.0){
      det = 1.0 / det;
    }
    final num tempy =  det * (a11 * b.y - a21 * b.x) ;
    out.x = det * (a22 * b.x - a12 * b.y);
    out.y = tempy;
  }

  /** Returns a String showing this matrix values. */
  String toString() =&gt; "$col1, $col2";
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="Matrix22">
<button class="show-code">Code</button>
new <strong>Matrix22</strong>([<a href="../box2d_html/Vector.html">Vector</a> c1 = null, <a href="../box2d_html/Vector.html">Vector</a> c2 = null]) <a class="anchor-link" href="#Matrix22"
              title="Permalink to Matrix22.Matrix22">#</a></h4>
<div class="doc">
<p>Constructs a new Matrix. Defaults to both columns being default vectors.</p>
<pre class="source">
Matrix22([Vector c1 = null, Vector c2 = null]) {
  if (c1 == null) c1 = new Vector();
  if (c2 == null) c2 = new Vector();
  col1 = c1;
  col2 = c2;
}
</pre>
</div>
</div>
<div class="method"><h4 id="Matrix22.copy">
<button class="show-code">Code</button>
new <strong>Matrix22.copy</strong>(<a href="../box2d_html/Matrix22.html">Matrix22</a> other) <a class="anchor-link" href="#Matrix22.copy"
              title="Permalink to Matrix22.Matrix22.copy">#</a></h4>
<div class="doc">
<p>Create a new Matrix equal to the given Matrix.</p>
<pre class="source">
Matrix22.copy(Matrix22 other)
    : col1 = new Vector.copy(other.col1),
      col2 = new Vector.copy(other.col2);
</pre>
</div>
</div>
<div class="method"><h4 id="Matrix22.fromAngle">
<button class="show-code">Code</button>
new <strong>Matrix22.fromAngle</strong>(num angle) <a class="anchor-link" href="#Matrix22.fromAngle"
              title="Permalink to Matrix22.Matrix22.fromAngle">#</a></h4>
<div class="doc">
<p>Constructs a new Matrix22 representing an angle.</p>
<pre class="source">
Matrix22.fromAngle(num angle)
    : col1 = new Vector(), col2 = new Vector() {
  setAngle(angle);
}
</pre>
</div>
</div>
</div>
<div>
<h3>Static Methods</h3>
<div class="method"><h4 id="mulTransMatrixAndVectorToOut">
<button class="show-code">Code</button>
void <strong>mulTransMatrixAndVectorToOut</strong>(<a href="../box2d_html/Matrix22.html">Matrix22</a> matrix, <a href="../box2d_html/Vector.html">Vector</a> vector, <a href="../box2d_html/Vector.html">Vector</a> out) <a class="anchor-link" href="#mulTransMatrixAndVectorToOut"
              title="Permalink to Matrix22.mulTransMatrixAndVectorToOut">#</a></h4>
<div class="doc">
<p>Multiply the given vector by the transpose of the given matrix and store
the result in the given parameter out.</p>
<pre class="source">
static void mulTransMatrixAndVectorToOut(Matrix22 matrix, Vector vector,
    Vector out) {
  num outx = vector.x * matrix.col1.x + vector.y * matrix.col1.y;
  out.y = vector.x * matrix.col2.x + vector.y * matrix.col2.y;
  out.x = outx;
}
</pre>
</div>
</div>
<div class="method"><h4 id="mulMatrixAndVectorToOut">
<button class="show-code">Code</button>
void <strong>mulMatrixAndVectorToOut</strong>(<a href="../box2d_html/Matrix22.html">Matrix22</a> matrix, <a href="../box2d_html/Vector.html">Vector</a> vector, <a href="../box2d_html/Vector.html">Vector</a> out) <a class="anchor-link" href="#mulMatrixAndVectorToOut"
              title="Permalink to Matrix22.mulMatrixAndVectorToOut">#</a></h4>
<div class="doc">
<p>Multiply the given vector by the given matrix and store
the result in the given parameter out.</p>
<pre class="source">
static void mulMatrixAndVectorToOut(Matrix22 matrix, Vector vector,
    Vector out) {
  num tempy = matrix.col1.y * vector.x + matrix.col2.y * vector.y;
  out.x = matrix.col1.x * vector.x + matrix.col2.x * vector.y;
  out.y = tempy;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="col1">
<button class="show-code">Code</button>
<a href="../box2d_html/Vector.html">Vector</a>         <strong>col1</strong> <a class="anchor-link"
            href="#col1"
            title="Permalink to Matrix22.col1">#</a>
        </h4>
        <div class="doc">
<pre class="source">
Vector col1;
</pre>
</div>
</div>
<div class="field"><h4 id="col2">
<button class="show-code">Code</button>
<a href="../box2d_html/Vector.html">Vector</a>         <strong>col2</strong> <a class="anchor-link"
            href="#col2"
            title="Permalink to Matrix22.col2">#</a>
        </h4>
        <div class="doc">
<pre class="source">
Vector col2;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="runtimeType">
<button class="show-code">Code</button>
final Type         <strong>runtimeType</strong> <a class="anchor-link"
            href="#runtimeType"
            title="Permalink to Matrix22.runtimeType">#</a>
        </h4>
        <div class="inherited-from">inherited from Object </div><div class="doc">
<p>A representation of the runtime type of the object.</p>
<pre class="source">
external Type get runtimeType;
</pre>
</div>
</div>
</div>
<div>
<h3>Operators</h3>
<div class="method"><h4 id="==">
<button class="show-code">Code</button>
bool <strong>operator ==</strong>(other) <a class="anchor-link" href="#=="
              title="Permalink to Matrix22.operator ==">#</a></h4>
<div class="doc">
<p>Returns true if given object is a Matrix22 and its col1 and col2 are equal
to the col1 and col2 of this Matrix22.</p>
<pre class="source">
bool operator ==(other) {
  return other is Matrix22 &amp;&amp; col1 == other.col1 &amp;&amp; col2 == other.col2;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="addLocal">
<button class="show-code">Code</button>
<a href="../box2d_html/Matrix22.html">Matrix22</a> <strong>addLocal</strong>(<a href="../box2d_html/Matrix22.html">Matrix22</a> other) <a class="anchor-link" href="#addLocal"
              title="Permalink to Matrix22.addLocal">#</a></h4>
<div class="doc">
<p>Adds the given matrix to this matrix. Returns this matrix.</p>
<pre class="source">
Matrix22 addLocal(Matrix22 other) {
  col1.x += other.col1.x;
  col1.y += other.col1.y;
  col2.x += other.col2.x;
  col2.y += other.col2.y;
  return this;
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="hashCode">
<button class="show-code">Code</button>
int <strong>hashCode</strong>() <a class="anchor-link" href="#hashCode"
              title="Permalink to Matrix22.hashCode">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Get a hash code for this object.</p>
<p>All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator <code>==</code>. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.</p>
<p>If a subclass overrides <code>hashCode</code> it should override the
equality operator as well to maintain consistency.</p>
<pre class="source">
external int hashCode();
</pre>
</div>
</div>
<div class="method"><h4 id="invertLocal">
<button class="show-code">Code</button>
<a href="../box2d_html/Matrix22.html">Matrix22</a> <strong>invertLocal</strong>() <a class="anchor-link" href="#invertLocal"
              title="Permalink to Matrix22.invertLocal">#</a></h4>
<div class="doc">
<p>Inverts this Matrix.</p>
<pre class="source">
Matrix22 invertLocal() {
  num a = col1.x, b = col2.x, c = col1.y, d = col2.y;
  num det = a * d - b * c;
  if (det != 0) {
    det = 1.0 / det;
  }
  col1.x = det * d;
  col2.x = -det * b;
  col1.y = -det * c;
  col2.y = det * a;
  return this;
}
</pre>
</div>
</div>
<div class="method"><h4 id="Matrix22">
<button class="show-code">Code</button>
new <strong>Matrix22</strong>([<a href="../box2d_html/Vector.html">Vector</a> c1 = null, <a href="../box2d_html/Vector.html">Vector</a> c2 = null]) <a class="anchor-link" href="#Matrix22"
              title="Permalink to Matrix22.Matrix22">#</a></h4>
<div class="doc">
<p>Constructs a new Matrix. Defaults to both columns being default vectors.</p>
<pre class="source">
Matrix22([Vector c1 = null, Vector c2 = null]) {
  if (c1 == null) c1 = new Vector();
  if (c2 == null) c2 = new Vector();
  col1 = c1;
  col2 = c2;
}
</pre>
</div>
</div>
<div class="method"><h4 id="Matrix22.copy">
<button class="show-code">Code</button>
new <strong>Matrix22.copy</strong>(<a href="../box2d_html/Matrix22.html">Matrix22</a> other) <a class="anchor-link" href="#Matrix22.copy"
              title="Permalink to Matrix22.Matrix22.copy">#</a></h4>
<div class="doc">
<p>Create a new Matrix equal to the given Matrix.</p>
<pre class="source">
Matrix22.copy(Matrix22 other)
    : col1 = new Vector.copy(other.col1),
      col2 = new Vector.copy(other.col2);
</pre>
</div>
</div>
<div class="method"><h4 id="Matrix22.fromAngle">
<button class="show-code">Code</button>
new <strong>Matrix22.fromAngle</strong>(num angle) <a class="anchor-link" href="#Matrix22.fromAngle"
              title="Permalink to Matrix22.Matrix22.fromAngle">#</a></h4>
<div class="doc">
<p>Constructs a new Matrix22 representing an angle.</p>
<pre class="source">
Matrix22.fromAngle(num angle)
    : col1 = new Vector(), col2 = new Vector() {
  setAngle(angle);
}
</pre>
</div>
</div>
<div class="method"><h4 id="multiplyVectorToOut">
<button class="show-code">Code</button>
void <strong>multiplyVectorToOut</strong>(<a href="../box2d_html/Vector.html">Vector</a> v, <a href="../box2d_html/Vector.html">Vector</a> out) <a class="anchor-link" href="#multiplyVectorToOut"
              title="Permalink to Matrix22.multiplyVectorToOut">#</a></h4>
<div class="doc">
<p>Multiply this matrix by a vector. Return the result through the given out
parameter.</p>
<pre class="source">
void multiplyVectorToOut(Vector v, Vector out) {
  num tempy = col1.y * v.x + col2.y * v.y;
  out.x = col1.x * v.x + col2.x * v.y;
  out.y = tempy;
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="noSuchMethod">
<button class="show-code">Code</button>
<strong>noSuchMethod</strong>(String name, List args) <a class="anchor-link" href="#noSuchMethod"
              title="Permalink to Matrix22.noSuchMethod">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p><code>noSuchMethod</code> is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to <code>noSuchMethod</code>. If <code>noSuchMethod</code>
returns a value, that value becomes the result of the original
invocation.</p>
<p>The default behavior of <code>noSuchMethod</code> is to throw a
<code>noSuchMethodError</code>.</p>
<pre class="source">
external Dynamic noSuchMethod(String name, List args);
</pre>
</div>
</div>
<div class="method inherited"><h4 id="Object">
<button class="show-code">Code</button>
const <strong>Object</strong>() <a class="anchor-link" href="#Object"
              title="Permalink to Matrix22.Object">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Creates a new <code>Object</code> instance.</p>
<p><code>Object</code> instances have no meaningful state, and are only useful
through their identity. An <code>Object</code> instance is equal to itself
only.</p>
<pre class="source">
const Object();
</pre>
</div>
</div>
<div class="method"><h4 id="setAngle">
<button class="show-code">Code</button>
void <strong>setAngle</strong>(num angle) <a class="anchor-link" href="#setAngle"
              title="Permalink to Matrix22.setAngle">#</a></h4>
<div class="doc">
<p>Set as a matrix representing a rotation.</p>
<pre class="source">
void setAngle(num angle) {
  num cosin = Math.cos(angle);
  num sin = Math.sin(angle);
  col1.setCoords(cosin, sin);
  col2.setCoords(-sin, cosin);
}
</pre>
</div>
</div>
<div class="method"><h4 id="setFrom">
<button class="show-code">Code</button>
void <strong>setFrom</strong>(<a href="../box2d_html/Matrix22.html">Matrix22</a> matrix) <a class="anchor-link" href="#setFrom"
              title="Permalink to Matrix22.setFrom">#</a></h4>
<div class="doc">
<p>Sets this matrix to be equal to the given matrix.</p>
<pre class="source">
void setFrom(Matrix22 matrix) {
  col1.setFrom(matrix.col1);
  col2.setFrom(matrix.col2);
}
</pre>
</div>
</div>
<div class="method"><h4 id="setFromColumns">
<button class="show-code">Code</button>
void <strong>setFromColumns</strong>(<a href="../box2d_html/Vector.html">Vector</a> v1, <a href="../box2d_html/Vector.html">Vector</a> v2) <a class="anchor-link" href="#setFromColumns"
              title="Permalink to Matrix22.setFromColumns">#</a></h4>
<div class="doc">
<p>Sets this matrix's columns equal to the given vectors, respectively.</p>
<pre class="source">
void setFromColumns(Vector v1, Vector v2) {
  col1.setFrom(v1);
  col2.setFrom(v2);
}
</pre>
</div>
</div>
<div class="method"><h4 id="setIdentity">
<button class="show-code">Code</button>
void <strong>setIdentity</strong>() <a class="anchor-link" href="#setIdentity"
              title="Permalink to Matrix22.setIdentity">#</a></h4>
<div class="doc">
<p>Set as the identity matrix.</p>
<pre class="source">
void setIdentity() {
  col1.setCoords(1, 0);
  col2.setCoords(0, 1);
}
</pre>
</div>
</div>
<div class="method"><h4 id="solveToOut">
<button class="show-code">Code</button>
void <strong>solveToOut</strong>(<a href="../box2d_html/Vector.html">Vector</a> b, <a href="../box2d_html/Vector.html">Vector</a> out) <a class="anchor-link" href="#solveToOut"
              title="Permalink to Matrix22.solveToOut">#</a></h4>
<div class="doc">
<pre class="source">
void solveToOut(Vector b, Vector out) {
  num a11 = col1.x, a12 = col2.x, a21 = col1.y, a22 = col2.y;
  num det = a11 * a22 - a12 * a21;
  if (det != 0.0){
    det = 1.0 / det;
  }
  final num tempy =  det * (a11 * b.y - a21 * b.x) ;
  out.x = det * (a22 * b.x - a12 * b.y);
  out.y = tempy;
}
</pre>
</div>
</div>
<div class="method"><h4 id="toString">
<button class="show-code">Code</button>
String <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to Matrix22.toString">#</a></h4>
<div class="doc">
<p>Returns a String showing this matrix values.</p>
<pre class="source">
String toString() =&gt; "$col1, $col2";
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
